import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

//单例基类
export default function Singleton<T>() {
    class Singleton {
        private static _instance: Singleton = null;
        public static get instance(): T {
            if (!Singleton._instance) {
                Singleton._instance = new this();
                Singleton._instance._init();
            }
            return <T>Singleton._instance;
        }

        protected constructor() { }

        public static release() {
            Singleton._instance = null;
        }

        protected _init() {

        }
    }

    return Singleton;
}